package common.cell;

import common.Constants.*;

class Cell {
    public var x: Int;
    public var y: Int;
    public var z: Int;

    public var char: String = "?";
    public var color: Int = COLOR_WHITE;

    var grid: GridImpl;

    public function new(grid: GridImpl, x: Int, y: Int, z: Int) {
        this.grid = grid;
        this.x = x;
        this.y = y;
        this.z = z;

        init();
    }

    /* LIFECYCLE METHODS */

    // Called when this cell is initialized.
    function init() {}

    // Called every update tick.
    public function update(key: Int) {}

    // Called when this cell is moved.
    public function moved() {}

    // Called when this cell is overwritten with another.
    public function destroyed() {}

    /* HELPFUL METHODS */

    // Moves from (x, y, z) to (tx, ty, tz).
    function move(tx: Int, ty: Int, tz: Int) {
        grid.setCell(x, y, z, new Empty(grid, x, y, z));
        grid.setCell(tx, ty, tz, this);
    }
}
